package adv6;

import adv7.AutoSaveThread;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class ChaoshiTest {
    public static void main(String[] args) {
        //亿点点暗示：一开始先读对象，没有，才能new
       SuperMarket sm=SuperMarket.get();
        Scanner in=new Scanner(System.in);
       if(sm==null){
           System.out.println("新店开张");
           sm=new SuperMarket();
           System.out.println("请输入店名:");
           sm.setName(in.next());
           System.out.println("请输入地址：");
           sm.setAddr(in.next());
       }
        AutoSaveThread ath=new AutoSaveThread(sm);
        ath.start();//!!!
        int choice=0;
        while(true){
            System.out.println("1:新会员开卡，2：查看，9：退出");
            choice=in.nextInt();
            if(choice==1){
                Vip v=new Vip();
                System.out.println("请输入会员卡号：");
                v.setNo(in.nextInt());
                System.out.println("姓名：");
                v.setName(in.next());
                System.out.println("手机号：");
                v.setPhone(in.next());
                System.out.println("密码:");
                v.setPass(in.next());
                sm.add(v);
            }else if(choice==2){
                sm.show();
            }else if(choice==9){
                SuperMarket.save(sm);
                //System.exit(0);
                ath.stopRuning();
                break;
            }
        }
    }
}
